import {baseEffects, baseReducers, baseState} from "../../../models/baseModel";
import * as request from "../../../services/CommonHttpService";
import AppService from "../../../common/AppService";
import moment from "moment";
export default {
  namespace: 'AutoEcg',

  state: {
    ...baseState,
    AutoEcg:[],
    AutoFilterEcg:[]
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    // 获取血压设备列表
    * AutoEcg({payload,callback}, {call, put}) {
      let result = yield call(request.commonGet, getBaseUrl(), {},payload, AppService.deviceUrl);
      const AutoEcg = result.map(value => {
        return {
          ...value,
          startTime: moment(value.startTime).format('YYYY-MM-DD HH:mm:ss SSS')
        };
      });
      yield put({
        type: 'initState',
        payload: {AutoEcg}
      });
    },
    * AutoFilterEcg({payload,callback}, {call, put}) {
      let result = yield call(request.commonGet, getBaseUrl2(), {},payload, AppService.deviceUrl);
      const AutoFilterEcg = result.map(value => {
        return {
          ...value,
          startTime: moment(value.startTime).format('YYYY-MM-DD HH:mm:ss SSS')
        };
      });
      yield put({
        type: 'initState',
        payload: {AutoFilterEcg}
      });
    },
  }

}

function getBaseUrl() {
  return "/mlnx_device/ecg/getAutoEcg";
}

function getBaseUrl2() {
  return "/mlnx_device/ecg/getAutoFilterEcg";
}
